#ifndef AISTRATEGY_H
#define AISTRATEGY_H

#include "board.h"
#include "rulechecker.h"
#include "pos.h"
#include <vector>
#include <utility>
#include <string>

// 计分走法结构体
struct ScoredMove {
    Pos from;
    Pos to;
    int score;
    ScoredMove(Pos f, Pos t, int s) : from(f), to(t), score(s) {}
};

// AI策略接口
class AIStrategy {
public:
    virtual ~AIStrategy() = default;
    
    // 电脑走棋
    virtual bool makeMove(Board& board, RuleChecker& ruleChecker) = 0;
    
    // 获取策略名称
    virtual std::string getStrategyName() const = 0;
    
    // 获取策略描述
    virtual std::string getStrategyDescription() const = 0;

protected:
    // 评估走法的基础函数（所有AI共用）
    int evaluateMove(const Board& board, const Pos& from, const Pos& to);
    
    // 检查是否会导致将帅照面
    bool willCauseFacingKings(const Board& board, const Pos& from, const Pos& to);
    
    // 获取棋子价值
    int getPieceValue(ChessDef::pieceID piece) const;
    
    // 计算开放线路数量（用于车炮）
    int countOpenLines(const Board& board, const Pos& pos);
};

// 简单AI策略 - 随机走法
class SimpleAIStrategy : public AIStrategy {
public:
    bool makeMove(Board& board, RuleChecker& ruleChecker) override;
    std::string getStrategyName() const override { return "简单"; }
    std::string getStrategyDescription() const override { return "随机选择合法走法"; }
};

// 中等AI策略 - 基础规则评估
class MediumAIStrategy : public AIStrategy {
public:
    bool makeMove(Board& board, RuleChecker& ruleChecker) override;
    std::string getStrategyName() const override { return "中等"; }
    std::string getStrategyDescription() const override { return "基于简单规则评估选择走法"; }

private:
    // 中等AI专用评估函数
    int evaluateMediumMove(const Board& board, const Pos& from, const Pos& to);
};

// 困难AI策略 - 高级算法
class HardAIStrategy : public AIStrategy {
public:
    bool makeMove(Board& board, RuleChecker& ruleChecker) override;
    std::string getStrategyName() const override { return "困难"; }
    std::string getStrategyDescription() const override { return "使用高级搜索算法"; }

private:
    // 困难AI专用评估函数
    int evaluateHardMove(Board& board, RuleChecker& ruleChecker, const Pos& from, const Pos& to, int depth);
    
    // 评估对手的最佳回应
    int evaluateBestOpponentMove(Board& board, RuleChecker& ruleChecker);
    
    // 局面评估函数
    int evaluateBoard(const Board& board);
};

#endif